package com.ait.oss.controller;


import com.ait.commonutils.Msg;
import com.ait.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduoss")
public class OssController {


    @Autowired
    private OssService ossService;


    //图片上传oss
    @PostMapping("up")
    public Msg uploadOssFile( @RequestParam("file") MultipartFile file){
        String s = ossService.uploadFileAvatar(file);
        if (!StringUtils.isEmpty(s)){return Msg.success().data("url",s);}

        return Msg.fail();
    }

    //视频上传oss
    @PostMapping("video")
    public Msg uploadVideo(MultipartFile file){
        Map<String, Object> id = ossService.uploadFileVideo(file);
        if(id!=null)return Msg.success().data(id);
        return Msg.fail();
    }


    //删除视频
    @DeleteMapping("delvideo")
    public Msg delVideo(String id){
        Boolean isNaN= ossService.DeleteFileVideo(id);
        if(isNaN)return Msg.success();
        return Msg.fail();
    }


    //排列删除视频
    @DeleteMapping("delBatchVideo")
    public Msg delBatchVideo(@RequestParam("videoList")List<String> videoList){
        System.out.println(videoList);
        Boolean isNaN= ossService.DeleteBatchFileVideo( videoList);
        if(isNaN)return Msg.success();
        return Msg.fail();
    }


    @GetMapping("getPlayAuth")
    public Msg getPlayAuth(@RequestParam("id")String id){
        String s = ossService.getplayAuths(id);
        return Msg.success().data("secret",s);
    }
}
